﻿namespace Chain.BLL
{
    using Chain.IDAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class GoodsNumber
    {
        private readonly Chain.IDAL.GoodsNumber dal = new Chain.IDAL.GoodsNumber();

        public int Add(Chain.Model.GoodsNumber model)
        {
            return this.dal.Add(model);
        }

        public bool ChenkOutShopGoodsNumber(int OutShopID, int GoodsID, decimal OutNumber)
        {
            return this.dal.ChenkOutShopGoodsNumber(OutShopID, GoodsID, OutNumber);
        }

        public DataSet CkeckInShopGoods(int intGoodsID, int intShopID)
        {
            return this.dal.CkeckInShopGoods(intGoodsID, intShopID);
        }

        public List<Chain.Model.GoodsNumber> DataTableToList(DataTable dt)
        {
            List<Chain.Model.GoodsNumber> list = new List<Chain.Model.GoodsNumber>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.GoodsNumber item = new Chain.Model.GoodsNumber();
                    if ((dt.Rows[i]["ID"] != null) && (dt.Rows[i]["ID"].ToString() != ""))
                    {
                        item.ID = int.Parse(dt.Rows[i]["ID"].ToString());
                    }
                    if ((dt.Rows[i]["GoodsID"] != null) && (dt.Rows[i]["GoodsID"].ToString() != ""))
                    {
                        item.GoodsID = int.Parse(dt.Rows[i]["GoodsID"].ToString());
                    }
                    if ((dt.Rows[i]["ShopID"] != null) && (dt.Rows[i]["ShopID"].ToString() != ""))
                    {
                        item.ShopID = int.Parse(dt.Rows[i]["ShopID"].ToString());
                    }
                    if ((dt.Rows[i]["Number"] != null) && (dt.Rows[i]["Number"].ToString() != ""))
                    {
                        item.Number = decimal.Parse(dt.Rows[i]["Number"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int ID)
        {
            return this.dal.Delete(ID);
        }

        public bool DeleteList(string IDlist)
        {
            return this.dal.DeleteList(IDlist);
        }

        public bool DeleteNumber(int GoodsID, int ShopID)
        {
            return this.dal.DeleteNumber(GoodsID, ShopID);
        }

        public bool Exists(int ID)
        {
            return this.dal.Exists(ID);
        }

        public DataSet GetAllGoodsidByShopID(int ShopID)
        {
            return this.dal.GetAllGoodsidByShopID(ShopID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public int GetGoodsCount(int ClassID, int ShopID)
        {
            return this.dal.GetGoodsCount(ClassID, ShopID);
        }

        public DataSet GetGoodsNumber(int intGoodsID, int intShopID)
        {
            return this.dal.GetGoodsNumber(intGoodsID, intShopID);
        }

        public DataSet GetGoodsNumber(string strGoodsCode, int intShopID)
        {
            return this.dal.GetGoodsNumber(strGoodsCode, intShopID);
        }

        public DataSet GetGoodsNumberDelServe(string strGoodsCode, int intShopID)
        {
            return this.dal.GetGoodsNumberDelServe(strGoodsCode, intShopID);
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, out resCount, strWhere);
        }

        public Chain.Model.GoodsNumber GetModel(int ID)
        {
            return this.dal.GetModel(ID);
        }

        public List<Chain.Model.GoodsNumber> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public decimal GetNumber(int goodsID, int shopID)
        {
            return this.dal.GetNumber(goodsID, shopID);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public DataSet GetShopIDListByGoods(int GoodsID)
        {
            return this.dal.GetShopIDListByGoods(GoodsID);
        }

        public void InitShopData()
        {
            this.dal.InitShopData();
        }

        public int InsertGoodsNumber(int intGoodsID)
        {
            return this.dal.InsertGoodsNumber(intGoodsID);
        }

        public int InsertGoodsNumber(int intGoodsID, int intShopID)
        {
            return this.dal.InsertGoodsNumber(intGoodsID, intShopID);
        }

        public int SyncGoods(int GoodsID)
        {
            return this.dal.SyncGoods(GoodsID);
        }

        public int SyncGoods(int GoodsID, List<int> ShopList)
        {
            return this.dal.SyncGoods(GoodsID, ShopList);
        }

        public int SyncGoods(int GoodsID, int ShopID)
        {
            return this.dal.SyncGoods(GoodsID, ShopID);
        }

        public int UpdataGoodsNumber(Chain.Model.GoodsNumber model)
        {
            return this.dal.UpdataGoodsNumber(model);
        }

        public bool UPdataInShopGoodsNumber(int OutShopID, int GoodsID, int OutNumber)
        {
            return this.dal.UPdataInShopGoodsNumber(OutShopID, GoodsID, OutNumber);
        }

        public bool UPdataOutShopGoodsNumber(int OutShopID, int GoodsID, decimal OutNumber)
        {
            return this.dal.UPdataOutShopGoodsNumber(OutShopID, GoodsID, OutNumber);
        }

        public bool Update(Chain.Model.GoodsNumber model)
        {
            return this.dal.Update(model);
        }

        public int UpdateGoodsNumber(int goodsID, decimal goodsNumber, int shopID)
        {
            return this.dal.UpdateGoodsNumber(goodsID, goodsNumber, shopID);
        }
    }
}

